package com.hackerrank.contests.aug13.challenges.ajourneytothemoon;

import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Solution {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt(), I = in.nextInt();
		Set<Integer>[] s = new HashSet[N];
		for(int i = 0; i < N; i++) {
			s[i] = new HashSet<Integer>();
			s[i].add(i);
		}
		for(int i = 0; i < I; i++) {
			int s1 = in.nextInt(), s2 = in.nextInt();
			if(s[s1] == s[s2])
				continue;
			for(int e : s[s2]) {
				s[s1].add(e);
				s[e] = s[s1];
			}
		}
		Set<Set<Integer>> l = new HashSet<Set<Integer>>();
		for(int i = 0; i < N; i++)
			l.add(s[i]);
		int c[] = new int[l.size()], i = 0, pc[] = new int[l.size()], p = 0;
		for(Set<Integer> ls : l)
			c[i++] = ls.size();
		for(i = 1; i < c.length; i++)
			pc[i] = pc[i - 1] + c[i - 1];
		for(i = 0; i < c.length; i++)
			p += c[i] * pc[i];
		System.out.println(p);
	}
}
